package com.example.firstjavamqtt.factory.strategy.callback;

import com.alibaba.fastjson.JSONObject;
import com.example.firstjavamqtt.model.base.Device;
import com.example.firstjavamqtt.service.base.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class HandleRegisterMsgStrategy implements HandleMessageStrategy{

    private static DeviceService deviceService;

    @Override
    public void handle(String msg) {
        Device device = JSONObject.parseObject(msg, Device.class);
        System.out.println(device);
        deviceService.registerDevice(device);
    }

    @Autowired
    public void setDeviceService(DeviceService deviceService) {
        HandleRegisterMsgStrategy.deviceService = deviceService;
    }
}
